local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.Server_PlayerObject());
local ConnectClass=_G.CommonOHOH.load.Connect();
local EventList = ServerOHOH.load.EventList();
local ServerEventManager = ServerOHOH.load.ServerEventManager();



function M.new(self)
	return M(self);
end;
function M.ctor(self, playerInst)
	_G.CommonOHOH.load.PlayerTool().CreateConnectEvent(self)
	M.super.ctor(self, playerInst);

end;



--已有数据，但是客户端player还未设置数据
function M.OnLogin(self)
	self.DataBase= self:GetComponent(ServerOHOH.load.Server_PlayerDataComponent());

end;


function M.SynchDataToClient(self,...)
	local keys={...}
	local netData={}
	for _,v in pairs(keys) do
		self.UserDataEvent:Action(v)
		local data=self.DataBase:GetData(v)
		assert(data~=nil,"Data==nil,Error Key="..v)
		if type(data)=="table" then
			netData[v]=data.__real
		else
			netData[v]=data
		end
	end
	ServerEventManager:Fire(self, EventList.synch_userdata, netData);
end


function M.FireMsgDataToClient(self,...)
	local keys={...}
	local netData={}
	for _,v in pairs(keys) do
		local data=self.DataBase:GetData(v)
		assert(data~=nil,"Data==nil,Error Key="..v)
		if type(data)=="table" then
			netData[v]=data.__real
		else
			netData[v]=data
		end
	end
	ServerEventManager:Fire(self, EventList.synch_userdata, netData);
end

--客户端已有数据
function M.OnLoginOver(self)
	
	self:AddComponent(_G.CommonOHOH.load.Common_MatchCtrl()); 

	self:AddComponent(_G.CommonOHOH.load.Common_PaveCtrl()); 
	self:AddComponent(_G.CommonOHOH.load.Common_ReadyCtrl()); 
	self:AddComponent(_G.CommonOHOH.load.Common_ShowCtrl()); 
	self:AddComponent(_G.CommonOHOH.load.CharacterAnimationCtrl());
	self:AddComponent(_G.CommonOHOH.load.Common_TrailCtrl()); 
	self:AddComponent(_G.CommonOHOH.load.Common_DrillCtrl());  
end;


function M.OnCharacterIn(self, Character)
	self.CharacterEnterEvent:Action(Character)
end;

function M.OnCharacterOut(self, Character)

end;


ServerOHOH.load.ServerFunctionManager():SetHandle(ServerOHOH.load.FunctionList().create_character, function(player)
	player:CreateCharacter();
end);


ServerOHOH.event_manager:RegistHandle(ServerOHOH.event_list.UpdDone, function(player)
	assert(player,"player==nil")
    local DataBase=player:GetComponent(ServerOHOH.load.Server_PlayerDataComponent())
	DataBase:SetData("upd",_G.CommonOHOH.config.Game.Upd.id)
end);

return M;
